﻿using System.Drawing;
using System.Windows.Forms;

namespace LocationAwareness
{
    /// <summary>
    /// Class is displaying an instance of a POI on client.
    /// </summary>
    public partial class PoiView : UserControl
    {
        private POI poi;
        private delegate void AddBitmap(Bitmap bit);

        /// <summary>
        /// Instanciating a PoiView
        /// </summary>
        /// <param name="p">Instance of POI to be displayed.</param>
        public PoiView(POI p)
        {
            InitializeComponent();

            poi = p;

            lbName.Text = poi.Name;
            lbCat.Text = poi.Categorie;
            lbDis.Text = poi.Distance;
            //pbPoiImage.Image = poi.PoiImage;
            Name = poi.Name;
        }

        public override DockStyle Dock
        {
            get
            {
                return base.Dock;
            }
            set
            {
                base.Dock = value;
            }
        }

        /// <summary>
        /// Sets Image of the represented POI
        /// </summary>
        /// <param name="bit">Image to be displayed.</param>
        public void SetBitmap(Bitmap bit)
        {
            if (this.InvokeRequired)
                this.Invoke(new AddBitmap(SetBitmap), new object[] { bit });
            else
            {
                pbPoiImage.Image = Functions.ScaleGraphics(bit, pbPoiImage.Width, pbPoiImage.Height);
            }
        }

        /// <summary>
        /// Image shown on instance.
        /// </summary>
        /// <returns>Instance of represented image.</returns>
        public Bitmap GetBitmap()
        {
            return (Bitmap)pbPoiImage.Image;
        }

        /// <summary>
        /// ImagePath of displayed POI.
        /// </summary>
        public string ImagePath
        {
            get
            {
                return poi.ImagePath;
            }
        }

        /// <summary>
        /// Categorie of displayed POI.
        /// </summary>
        public string Categorie
        {
            get
            {
                return poi.Categorie;
            }
        }

        /// <summary>
        /// ObjectID of displayed POI.
        /// </summary>
        public string ObjectID
        {
            get
            {
                return poi.ObjectID;
            }
        }
    }
}
